package springdoc.configuration;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * 访问地址：http://localhost:8082/swagger-ui/index.html#/
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("springdoc.web"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建一个ApiInfo对象
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 文档标题
                .title("SpringBoot整合Swagger3")
                // 简介
                .description("更多请咨询服务开发者小龍")
                // 作者信息：作者姓名、作者地址、作者邮箱
                .contact(new Contact("小龍", "https://blog.csdn.net/wangzhilong1996", "123456@qq.com"))
                // 版本号
                .version("1.0")
                .build();
    }

    /**
     * 开发A组的接口
     *
     * @return
     */
    @Bean
    public Docket docketA() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("A");
    }

    /**
     * 开发B组的接口
     *
     * @return
     */
    @Bean
    public Docket docketB() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("B");
    }
}


